<?php

/**
 * This is the model class for table "mtuan_bangcap".
 *
 * The followings are the available columns in table 'mtuan_bangcap':
 * @property integer $id
 * @property string $name
 * @property string $update_date
 * @property string $alias
 */
class Nhatuyendung extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Bangcap the static model class
	 */
	public $matkhau_confirm = "";
	public $security_code = "";
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	public function primaryKey()
	{
	    return 'id';
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'nhatuyendung';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('tendangnhap', 'required'),
			array('tendangnhap', 'length', 'min'=>6),
			array('tendangnhap', 'length', 'max'=>20),
			array('tendangnhap', 'unique'),
			array('matkhau', 'required'),
			array('matkhau', 'length', 'min'=>6),
			array('matkhau', 'length', 'max'=>30),
			array('matkhau', 'compare', 'compareAttribute'=>'matkhau_confirm'),
			array('hoten', 'required'),
			array('hoten', 'length', 'min'=>3),
			array('email', 'required'),
			array('email', 'email'),
			array('email', 'unique'),
			array('diachi', 'required'),
			array('id_quocgia', 'required'),
			array('id_tinh_thanhpho', 'required'),
			array('dienthoaiban', 'required'),
			array('dienthoaiban', 'numerical', 'integerOnly' => true),
			array('dtdd', 'numerical', 'integerOnly' => true),
			array('cty_ten', 'required'),
			array('cty_id_loaihinhhoatdong', 'required'),
			array('cty_motangan', 'required'),
			array('cty_motangan', 'length', 'min'=>50),
			array('cty_motangan', 'length', 'max'=>5000),
			array('security_code', 'length', 'max'=>5000),
			array('security_code', 'required'),
    		array('security_code', 'captcha'),
		);
	}
	public function beforeSave()
	{
	       $this->matkhau = md5($this->matkhau);
	       $this->active_code = md5($this->tendangnhap.$this->matkhau.$this->email);
	       $this->status = 0;
	       $this->published = 0;
	       $this->alias = $this->tendangnhap;
	        return parent::beforeSave();
	}
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'tendangnhap' => 'Tên đăng nhập',
			'matkhau' => 'Mật khẩu',
			'hoten' => 'Họ và tên',
			'email' => 'Email',
			'diachi' => 'Địa chỉ',
			'id_quocgia' => 'Quốc gia',
			'id_tinh_thanhpho' => 'Tỉnh/Thành phố',
			'dienthoaiban' => 'Điện thoại',
			'dtdd' => 'ĐTDĐ',
			'cty_ten' => 'Tên công ty',
			'cty_id_loaihinhhoatdong' => 'Lĩnh vực hoạt động',
			'cty_motangan' => 'Mô tả ngắn',
			'security_code' => 'Mã xác nhận',
		);
	}

}